<%--
  Created by IntelliJ IDEA.
  User: 吴壮壮
  Date: 2021/8/28
  Time: 13:50
  To change this template use File | Settings | File Templates.
--%>
<%@page pageEncoding="UTF-8" language="java" contentType="text/html;UTF-8" %>

<a href="javascript:void(0);" id="testAjax">访问springmvc后台controller</a><br/>
<a href="javascript:void(0);" id="testAjaxPojo">访问springmvc后台controller，传递Json格式POJO</a><br/>
<a href="javascript:void(0);" id="testAjaxList">访问springmvc后台controller，传递Json格式List</a><br/>
<a href="javascript:void(0);" id="testAjaxReturnString">访问springmvc后台controller，返回字符串数据</a><br/>
<a href="javascript:void(0);" id="testAjaxReturnJson">访问springmvc后台controller，返回Json数据</a><br/>
<a href="javascript:void(0);" id="testAjaxReturnJsonList">访问springmvc后台controller，返回Json数组数据</a><br/>
<br/>
<a href="javascript:void(0);" id="testCross">跨域访问</a><br/>

<form action="/fileUpLoad" method="post" autocomplete="off" enctype="multipart/form-data">
    文件上传：<input type="file" name="file"><br>
    文件上传：<input type="file" name="file"><br>
    <button type="submit">上传</button>
</form>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>

<script type="text/javascript">

   /* let user={
        "username":"zhangsan",
        "age":"25"
    }*/
  $(function () {

      $("#testAjax").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller",
              data:"message",
              dataType:"text",
              contentType:"application/json",
              success:function (data) {
                  alert(data)
              }
          })
      })



      $("#testAjaxPojo").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller02",
              data:'{"username":"zhangsan","age":39}',
              dataType:"text",
              contentType:"application/json",
              success:function (data) {
                  alert(data)
              }
          })
      })



      $("#testAjaxList").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller03",
              data:'[{"username":"zhangsan","age":39},{"username":"lisi","age":25}]',
              dataType:"text",
              contentType:"application/json",
              success:function (data) {
                  alert(data.length)
              }
          })
      })




      $("#testAjaxReturnString").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller04",
              data:"message",
              dataType:"text",
              contentType:"application/json",
              success:function (data) {
                  alert(data)
              }
          })
      })



      $("#testAjaxReturnJson").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller05",
              dataType:"json",
              data:"message",
              contentType:"application/json",
              success:function (data) {
                  alert(data)
              }
          })
      })



      $("#testAjaxReturnJsonList").click(function () {
          $.ajax({
              type:"post",
              url:"ajaxcontroller06",
              dataType:"json",
              data:"message",
              contentType:"application/json",
              success:function (data) {
                  alert(data[0])
              }
          })
      })





  })


</script>
